package com.hncic.tx.center.common.util;

import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.dao.support.DataAccessUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

/**
 * @author smj E-mail: 463136320@qq.com
 * @created 2017年8月18日 上午10:42:03
 * @since jdk1.8 
 * @version 1.0
 * @describe 
 */

public class UtilJdbc {

	public static <T> T queryForObject(JdbcTemplate template, String sql, RowMapper<T> rowMapper, Object... args)
			throws DataAccessException {
		List<T> results = template.query(sql, rowMapper, args);
		return results.isEmpty() ? null : DataAccessUtils.requiredSingleResult(results);
	}
}
